﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace KINLO.UI.Main.ValidationRules
{
    public class IPAddressValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            //IP 地址检验
            Regex regex = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$");
            var str = value.ToString();
            var result= regex.IsMatch(str);
            if (result)
            {
              return  new ValidationResult(true, null);
            }
            else
            {
               return new ValidationResult(false, "请输入正确的IP地址");

            }
        }
    }
}
